//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.comprosoft.telnet.server;

import com.comprosoft.telnet.io.TextAreaHandler;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.LayoutManager;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class ServerControl {
    private JFrame frmTelnetServerControl;
    private JLabel lblRunning;

    public static void main(String[] args) {
        final JTextArea ta = setUpLoggers();
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    ServerControl window = new ServerControl(ta);
                    window.frmTelnetServerControl.setVisible(true);
                } catch (Exception var2) {
                    var2.printStackTrace();
                }

            }
        });
    }

    public ServerControl(JTextArea ta) {
        this.initialize(ta);
        Runnable r = new Runnable() {
            public void run() {
                TelnetServer server = new TelnetServer((String)null);
                server.run();
                ServerControl.this.serverNotRunning();
            }
        };
        (new Thread(r)).start();
    }

    private void initialize(JTextArea ta) {
        this.frmTelnetServerControl = new JFrame();
        this.frmTelnetServerControl.setResizable(false);
        this.frmTelnetServerControl.setBackground(Color.BLACK);
        this.frmTelnetServerControl.setTitle("Telnet Server Control");
        this.frmTelnetServerControl.setBounds(100, 100, 570, 439);
        this.frmTelnetServerControl.setDefaultCloseOperation(3);
        this.frmTelnetServerControl.getContentPane().setLayout((LayoutManager)null);
        JLabel lblServerControl = new JLabel("Telnet Server Control");
        lblServerControl.setForeground(new Color(255, 127, 80));
        lblServerControl.setFont(new Font("Times New Roman", 1, 26));
        lblServerControl.setHorizontalAlignment(0);
        lblServerControl.setBounds(124, 11, 314, 35);
        this.frmTelnetServerControl.getContentPane().add(lblServerControl);
        JLabel lblStatus = new JLabel("Status:");
        lblStatus.setHorizontalAlignment(0);
        lblStatus.setFont(new Font("Times New Roman", 0, 18));
        lblStatus.setBounds(200, 57, 89, 35);
        this.frmTelnetServerControl.getContentPane().add(lblStatus);
        this.lblRunning = new JLabel("Running");
        this.lblRunning.setForeground(new Color(0, 128, 0));
        this.lblRunning.setHorizontalAlignment(2);
        this.lblRunning.setFont(new Font("Times New Roman", 0, 18));
        this.lblRunning.setBounds(274, 57, 124, 35);
        this.frmTelnetServerControl.getContentPane().add(this.lblRunning);
        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setBounds(10, 138, 542, 226);
        this.frmTelnetServerControl.getContentPane().add(scrollPane);
        JLabel lblLog = new JLabel("Server Log:");
        lblLog.setFont(new Font("Tahoma", 2, 16));
        lblLog.setHorizontalAlignment(0);
        lblLog.setBounds(221, 113, 119, 27);
        this.frmTelnetServerControl.getContentPane().add(lblLog);
        scrollPane.setViewportView(ta);
        JButton btnHide = new JButton("Hide Window*");
        btnHide.setFont(new Font("Dialog", 1, 10));
        btnHide.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent arg0) {
                ServerControl.this.frmTelnetServerControl.setVisible(false);
            }
        });
        btnHide.setBounds(10, 377, 119, 23);
        this.frmTelnetServerControl.getContentPane().add(btnHide);
        JLabel lblHide = new JLabel("*Hiding window means server will need to be closed from Task Manager");
        lblHide.setFont(new Font("Tahoma", 1, 10));
        lblHide.setBounds(136, 381, 428, 14);
        this.frmTelnetServerControl.getContentPane().add(lblHide);
    }

    private static JTextArea setUpLoggers() {
        Logger rootLogger = Logger.getLogger("");
        TextAreaHandler handle = new TextAreaHandler();
        rootLogger.addHandler(handle);
        return handle.getTextArea();
    }

    public void serverRunning() {
        this.lblRunning.setForeground(new Color(0, 128, 0));
        this.lblRunning.setText("Running");
    }

    public void serverNotRunning() {
        this.lblRunning.setForeground(new Color(255, 0, 0));
        this.lblRunning.setText("Not Running");
    }
}
